using UnityEngine;

namespace JobsTutorialSample.Step1
{
    public class FindNearest : MonoBehaviour
    {
        void Update()
        {
            Vector3 pos = default;
            float nearestDistSq = float.MaxValue;
            foreach (var targetTrans in Spawner.TargetTransforms)
            {
                float distSq = (targetTrans.localPosition - transform.localPosition).sqrMagnitude;
                if (distSq < nearestDistSq)
                {
                    nearestDistSq = distSq;
                    pos = targetTrans.localPosition;
                }
            }

            Debug.DrawLine(transform.localPosition, pos);
        }
    }
}